<%@ page language="java" contentType="text/html; charset=utf8"%>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title></title>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/statics/css/page.css">
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/statics/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/statics/easyui/themes/icon.css">
	<script type="text/javascript" src="${pageContext.request.contextPath}/statics/js/form.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/statics/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/statics/easyui/jquery.easyui.min.js"></script>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/statics/css/form.css">
	<script>
		$(function(){
			$("#id").val('${role.id}');
			$("#name").val('${role.name}');
			$("#alias").val('${role.alias}');
			$("#description").val('${role.description}');
			var available = eval('${role.available}');
			if(available){
				$("input[name='available']:first").attr("checked", "checked");
			} else {
				$("input[name='available']:last").attr("checked", "checked");
			}
			$("#parent").combobox({
				url:'${pageContext.request.contextPath}/admin/role/getparentmodel',
				textField:'name',
				valueField:'id',
				panelHeight:100,
				onLoadSuccess:function(){
					$("#parent").combobox("setValue", '${role.parent.id}');
				}
			});
			$("#btnCancel").click(function(){
				close();
			});
			$("#btnOk").click(function(){
				$.ajax({
					url:'${pageContext.request.contextPath}/admin/role/modifymodel',
					type:"post",
					dataType:'html',      
					data:getData(),
					success:function(data){
						close();
					}
				})
			})
		});
		function getData(){
			var res = {};
			res.id = $("#id").val();
			if($("#name").val().length > 0){
				res.name = $("#name").val();
			}
			if($("#alias").val().length > 0){
				res.alias = $("#alias").val();
			}
			if($("#description").val().length > 0){
				res.description = $("#description").val();
			}
			var radio = $("input[name='available']:checked");
			if(radio.length > 0){
				res.available = $("input[name='available']:checked").val();
			} else {
				res.available = false;
			}
			if($("#parent").combotree("getValue").length > 0){
				res["parent.id"]= $("#parent").combotree("getValue");
			}
			return res;
		}
	</script>
</head>
<body>
	<form id="form" class="lv-form-container">
		<input type="hidden" id="id"/>
		<div class="lv-control-row">
			<div class="lv-label">角色名称</div>
			<input type="text" id="name" class="lv-control"/>
		</div>
		<div class="lv-control-row">
			<div class="lv-label">角色别名</div>
			<input type="text" id="alias" class="lv-control"/>
		</div>
		<div class="lv-control-row">
			<div class="lv-label">父角色</div>
			<select class="lv-control" id="parent">
			</select>
		</div>
		<div class="lv-control-row">
			<div class="lv-label">描述</div>
			<input type="text" id="description" class="lv-control"/>
		</div>
		<div class="lv-control-row">
			<div class="lv-label">可用性</div>
			<input type="radio" name="available" class="lv-control" style="width:25px;" value="true"/><span>可用</span>
			<input type="radio" name="available" class="lv-control" style="width:25px;"  value="false"/><span>禁用</span>
		</div>
		<div class="lv-control-row">
			<div class="lv-btn" id="btnCancel">取消</div>
			<div class="lv-btn" id="btnOk">确定</div>
		</div>
	</form>
</body>
</html>